;
(function() {

	var skill = {
		//统计每日交易金额
		statisAchsByDate: function(options) {
			// console.log(from, to);
			var to = options.to;
			var from = options.from;
			to = parseInt(to) || +new Date; //大 time，如果没有指定，就算现在
			from = parseInt(from) || +new Date(new Date(to).toDateString()); //小 time，如果没有指定，就算to时间的凌晨
			console.log(from, to);

			var resDateMap = {};
			var res = [];
			//找出已经完成支付的订单
			var achs = this.getAchs(null, null, function filter(ach) {
				return ach.isEndPay();
			});
			//如果需要过滤订单类型。
			var filter_by_pay_method = helper.boolean_parse(options.filter_by_pay_method);
			console.log(options.filter_pay_method_list)
			if (filter_by_pay_method && Array.isArray(options.filter_pay_method_list) && options.filter_pay_method_list.length) {
				achs = achs.filter(function(ach) {
					return options.filter_pay_method_list.indexOf(ach.info.pay_method) !== -1
				})
			}
			achs.forEach(function(ach) {
				console.log(new Date(ach.create_time).format("yyyy-MM-dd"));
				if (to > ach.create_time && ach.create_time > from) {
					var date_str = new Date(ach.create_time).toDateString();
					var data_mm = +new Date(date_str);
					//按日期分类
					(resDateMap[data_mm] || (resDateMap[data_mm] = [])).push(ach)
				}
			});
			console.log(resDateMap);
			Object.keys(resDateMap).forEach(function(data_mm) {
				var ach_list = resDateMap[data_mm];
				var total_cash = 0;
				var achs = ach_list.map(function(ach) {
					total_cash += ach.getCash();
					return ach._id
				});
				res.push({
					time: data_mm,
					achs: achs,
					total_cash: total_cash
				});
			});
			res.sort(function(A, B) {
				return A.time - B.time
			});
			return {
				to: to,
				from: from,
				filter_by_pay_method: !!filter_by_pay_method,
				filter_pay_method_list: options.filter_pay_method_list,
				type: "date",
				statis_info: res
			}
		}
	};
	module.exports = skill;
	var db = require("../db/index");
	var DomainCon = require("../domain/_con");
	var GoodsCon = require("../goods/_con");
	var UserCon = require("../../core/user/_con");
	var BusCon = require("../../core/bus/_con");
	var AchCon = require("../ach/_con");
	var ClassifyCon = require("../bus.classify/_con");
	var TagCon = require("../bus.tag/_con");
	var LeagueCon = require("../league/_con");
	var BuffCon = require("../buff/_con");
	var BusUserBindCon = require("../bus_user_bind/_con");
	var BusGuideCon = require("../bus.guide/_con");
	var CommentCon = require("../comment/_con");
	var config = require("../_include/config");
	var data_cut = require("../_include/data_cut");
	var helper = require("../_include/helper");
	var md5 = require("../_include/md5");
	var $Object = require("../_include/$.Object");
	var $Array = require("../_include/$.Array");
	var tld = require('tldjs');
	var Fiber = require('fibers');
	var fs = require("fs");
	var mail_sendmail_content = fs.readFileSync(__dirname + "/mail.sendmail.html").toString();
	var emailSender = require("../../core/_include/email");
}());